
function loadUserMainTree(divID) {
    $.fn.zTree.init($("#" + divID), setting0);
}
function addTab(title, url) {
    if ($('#tt').tabs('exists', title)) {
        $('#tt').tabs('select', title);
    } else {
        var content = '<iframe frameborder="0" style="overflow:hidden;width:100%;height:99%; " src="' + path_home +"/"+ url + '" ></iframe>';
        $('#tt').tabs('add', {
            title: title,
            content: content,
            closable: true
        });
        
    }
}
//刷新当前标签Tabs
function RefreshTab(currentTab) {
    var url = $(currentTab.panel('options')).attr('href');
    $('#tabs').tabs('update', {
        tab: currentTab,
        options: {
            href: url
        }
    });
    currentTab.panel('refresh');
}
function index_main_tab_close1() {
    var tabTitle;
    $(".tabs li").each(function (index, obj) {
        tabTitle = $(".tabs-closable", this).text();
        if (tabTitle == $("#tabsRClickDoSaveValueID").val()) {
            $("#tt").tabs("close", tabTitle);
            return;
        }
    });
}
function index_main_tab_close() {
    $(".tabs li").each(function (index, obj) {
        var tab = $(".tabs-closable", this).text();
        $(".easyui-tabs").tabs('close', tab);
    });
}
function index_main_tab_close_other() {
    $(".tabs li").each(function (index, obj) {
        var tabTitle = $(".tabs-closable", this).text();
        if (tabTitle != $("#tabsRClickDoSaveValueID").val()) {
            $("#tt").tabs("close", tabTitle);
        }
    });
}
function index_main_tab_reflash() {
    var currentTab = $('#tt').tabs('getSelected');
    var url = $(currentTab.panel('options')).attr('href');
    $('#tt').tabs('update', {
        tab: currentTab,
        options: {
            href: url
        }
    });
    currentTab.panel('refresh');
}

var zTree;
var demoIframe;

var setting = {
  view: {
    dblClickExpand: false,
    showLine: true,
    selectedMulti: false
  },
  data: {
    simpleData: {
      enable: true,
      idKey: "id",
      pIdKey: "pId",
      rootPId: ""
    }
  },
  callback: {
    beforeClick: function (treeId, treeNode) {
      var zTree = $.fn.zTree.getZTreeObj("divID_Tree_Main");
      if (treeNode.file) {
        addTab(treeNode.name, treeNode.file);
        zTree.selectNode(zTree.getNodeByParam("id", treeNode.id));
        return false;
      }
    }
  }
};
var zNodes;

$(document).ready(function () {
    $.ajax({
        type: "get",
        url: path_home+"/sysPower/readMenu",
        dataType:'json',
        success: function(data){
            zNodes = data;
            var t = $("#divID_Tree_Main");
            t = $.fn.zTree.init(t, setting, zNodes);
            var zTree = $.fn.zTree.getZTreeObj("divID_Tree_Main");
            // zTree.selectNode(zTree.getNodeByParam("id", 101));
        }
    });
});
